package openai

import (
	"encoding/json"
	"aifuture.cloud/pkg/app"
	"aifuture.cloud/pkg/openai/sdk"
	"github.com/gin-gonic/gin"
)

//云服务器路由注册
func RouterRegister(r *gin.Engine) {
	groupVersion := r.Group("/v1/openai")
	{
		ecsGrouop := groupVersion.Group("/ecs")
		{
			ecsGrouop.GET("/test", func(c *gin.Context) {
				appG := app.Gin{C: c}
				sdk.SetUp()
				content, err := sdk.OpenAIInstance.Request()
				if err != nil {
					appG.ResponseError(1, err.Error())
				}
				isFall := sdk.ValidateJSON(string(content), &sdk.FallbackData{})
				if isFall {
					appG.ResponseError(1, "网络错误")
				}
				json.Unmarshal(content, &sdk.Response)
				appG.ResponseSuccess(sdk.Response)
			})
		}
	}
}
